﻿//======================================================================
//
//        Copyright (C) 2015   
//        All rights reserved
//
//        filename : NotSaleCard
//        description : 未售问题卡回收
//        created by XXX at  20150821
//
//======================================================================
using System;
using CardLogistics.Web.Components;
using System.Data;
using System.Text;

namespace CardLogistics.Web.MainPage.CardRecovery.NotSaleCard
{
    public partial class ListInfo : BasePage
    {
        private static readonly CardLogistics.DAL.CardRecovery.NotSaleCardData DAL = new DAL.CardRecovery.NotSaleCardData();
        protected void Page_Load(object sender, EventArgs e)
        {
            WebUserControl_ToolBar1.DeleteEvent += new EventHandler(WebUserControl_ToolBar1_DeleteEvent);
            if (!IsPostBack)
            {
                BindRpt();
            }
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WebUserControl_ToolBar1_DeleteEvent(object sender, EventArgs e)
        {
            string delId = this.hdf_Id.Value;
            if (!string.IsNullOrEmpty(delId))
            {
                string[] ids = delId.TrimEnd(',').Split(',');
                int resCount = 0;
                for (int i = 0; i < ids.Length; i++)
                {
                    string resStr = DAL.Delete(ids[i]);
                    if (resStr.Split(',')[0] == "ok")
                        resCount++;
                }
                BindRpt();
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        private void BindRpt()
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            if (Mid == "100900")
            {
                sbStr.Append(" INFOTYPE=0 ");//制卡坏卡
            }
            else
            {
                sbStr.Append(" INFOTYPE=1 ");//未售问题卡
            }
            if (txt_RECOVERYNO.Text.Trim().Length > 0)
                sbStr.Append(" and RECOVERYNO like '%" + txt_RECOVERYNO.Text.Trim().ToUpper() + "%' ");//回收单号
            if (txt_StartRECOVERYDATE.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(RECOVERYDATE,'yyyy-MM-dd')>='" + txt_StartRECOVERYDATE.Text.Trim() + "'");//入库开始日期
            if (txt_EndRECOVERYDATE.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(RECOVERYDATE,'yyyy-MM-dd')<='" + txt_EndRECOVERYDATE.Text.Trim() + "'");//入库结束日期
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_notsalecard", "ID", " ADDTIME ", WebPageSize, WebPageIndex,sbStr.ToString(), "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            BindRpt();
        }
    }
}